/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kindergarden.at.google;

import java.sql.ResultSet;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;


/**
 *
 * @author paja0902
 */
public class RowListener implements ListSelectionListener
{
    @Override
    public void valueChanged(ListSelectionEvent event)
    {   
        System.out.println("Value Changed");
        if(event.getValueIsAdjusting())
            return;
        outputSelection(event);
    }



        private void outputSelection(ListSelectionEvent event)
        {
            try
            {   
                
                MyTabelModel getIdentifier = new MyTabelModel();
//                getIdentifier.getValueAt(GUI.table.getSelectedRow(), 1);
  
//                String tst = getIdentifier.getValueAt(GUI.table.getSelectedRow(), GUI.table.getSelectedColumn()).toString();
                String tst = GUI.table.getValueAt(GUI.table.getSelectedRow(), 1).toString();
                
                System.out.println("HEJSANAS "+tst);
                
                System.out.println("Fetching data from database");
                Statement s  = DatabaseConnection.connection.createStatement();
                ResultSet rs =  s.executeQuery("SELECT * FROM child where sin_num ="+tst);
                rs.next();
                GUI.info.append("Namn: " + rs.getString("name") + "\n");
                GUI.info.append("Personnummer: " + rs.getString("sin_num") + "\n" );
                GUI.info.append("Hemtelefonnummer: " + rs.getString("home_phone_number") + "\n");
                GUI.info.append("Hemtelefonnummer #2: " + rs.getString("home_phone_number2") + "\n");
                GUI.info.append("Närvarande: " + rs.getString("attendence") + "\n");
                GUI.info.append("Närvarotid: " + rs.getString("attendence_time") + "\n");
                GUI.info.append("Kommentar: " + rs.getString("comment") + "\n");
//                GUI.info.append(rs.getString("") + "\n");
//                GUI.info.append(rs.getString("") + "\n");
//                GUI.info.append(rs.getString("") + "\n");
//                GUI.info.append(rs.getString("") + "\n");
//                GUI.info.append(rs.getString("") + "\n");
//                GUI.info.append(rs.getString("") + "\n");
//                GUI.info.append(rs.getString("") + "\n");
//                GUI.info.append(rs.getString("") + "\n");
//                GUI.info.append(rs.getString("") + "\n");

                
               
                
//                System.out.println("ASSIGN");
//                String str = s.getResultSet().getString("name");
//                System.out.println(s.getResultSet().getCursorName());
//                System.out.println(s.getResultSet().getString("name"));
                s.close();
            }
            catch (SQLException ex)
            {
                Logger.getLogger(RowListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }


}